﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using Website.Logger;
using DAL;
using BOL;
using System.Web.Script.Services;
using System.Web.Services;
using WebLib;
using UtilityExtensions;
using System.Globalization;

namespace UILGestion.AlmacenAdmin
{
    public partial class CierreKardexForm : System.Web.UI.Page
    {
         protected void Page_Load(object sender, EventArgs e)
        {
            try
            {


                if (!Page.IsPostBack)
                {

                    idObra.Value = (string)Request.QueryString["idObra"];
                    idAlmacen.Value = (string)Request.QueryString["idAlmacen"];

                    menuObraCtrl1.loadMenuAlmacen(int.Parse(idObra.Value), int.Parse(idAlmacen.Value)); 

                    
                    
                    FormatForm();

               

                }


            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }

        }

         private void FormatForm()
         {

             

             mesDropDownList.DataValueField = "idinternal";
             mesDropDownList.DataTextField = "descripcion";

             anioDropDownList.DataValueField = "idinternal";
             anioDropDownList.DataTextField = "descripcion";



             



             mesDropDownList.DataSource = new BOL.ListValueBL().GetMeses();
             mesDropDownList.DataBind();

             anioDropDownList.DataSource = new BOL.ListValueBL().GetAniosCierre();
             anioDropDownList.DataBind();
             
             BOL.KardexBL d= new KardexBL();
             tipoCambioInput.Text = d.GetTipoCambioUltimoCierre(0, 0).ToString();

         }

         protected void Button1_Click(object sender, EventArgs e)
         {
             try
             {
                 BOL.KardexBL k = new KardexBL();
                 int idalmacen = int.Parse(idAlmacen.Value);
                 short anio=short.Parse(anioDropDownList.SelectedValue);
                 short mes=short.Parse(mesDropDownList.SelectedValue);
                 decimal tp=decimal.Parse(tipoCambioInput.Text);
                 
                 k.AddCierre(anio, mes, idalmacen, tp, ObservacionTxt.Text);
                 SaldoKardexGrid1.DataBind();
                 updateCierre.Update();

             }
             catch (SqlException sqlex)
             {
                 WebServerSideSqlError.Log(sqlex);
                 ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                  "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


             }
             catch (Exception ex)
             {
                 WebServerSideError.Log(ex);
                 ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                  "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

             }
         }


        
    }
}